/*
 * Created by Jaren at 2023/9/25 16:13
 */
import 'package:binary/binary.dart';

import '../../base/vehicle_data.dart';

class ESettings extends Settings {
  static const defaultTurningSensitivity = 50;
  static const defaultPedalSensitivity = defaultTurningSensitivity;
  static const autoTurningSensitivity = 101;
  static const autoPedalSensitivity = autoTurningSensitivity;

  /// 普通骑行模式下，限速值
  static const speedLimitOnNormalMode = 1800;

  /// 转向灵敏度
  Uint16 turningSensitivity = Uint16.zero;

  /// 踏板灵敏度
  Uint16 pedalSensitivity = Uint16.zero;

  /// 平衡零点
  Int16 angleZ = Int16.zero;

  /// 骑行模式
  ERidingMode ridingMode = ERidingMode.newbie;

  /// 限速
  Uint16 speedLimit = Uint16.zero;

  /// 后退超速报警开关
  Uint4 backwardOverSpeedAlert = Uint4.zero;

  /// 氛围灯模式
  Uint8 lightEffectMode = Uint8.zero;

  /// 氛围灯颜色，RGB
  int lightEffectColor = 0;

  /// 轮毂氛围灯开关
  Uint8 wheelLightEffectState = Uint8.zero;

  /// 还需骑行 x km可切换至普通模式(关闭限速)
  int mileageNeed2Ride2SwitchNormalRidingMode = 100;

  @override
  int length() {
    return 0;
  }

  @override
  String toString() {
    return 'ESettings{turningSensitivity: $turningSensitivity, pedalSensitivity: $pedalSensitivity, angleZ: $angleZ, ridingMode: $ridingMode, speedLimit: $speedLimit, backwardOverSpeedAlert: $backwardOverSpeedAlert, lightEffectMode: $lightEffectMode, lightEffectColor: $lightEffectColor, wheelLightEffectState: $wheelLightEffectState, mileageNeed2Ride2SwitchNormalRidingMode: $mileageNeed2Ride2SwitchNormalRidingMode}';
  }

  /// 是否为自动转向灵敏度
  bool isTurningSensitivityOnAutoMode([int? sensitivity]) {
    sensitivity ??= turningSensitivity.value;
    return sensitivity == autoTurningSensitivity;
  }

  /// 是否为自动踏板灵敏度
  bool isPedalSensitivityOnAutoMode([int? sensitivity]) {
    sensitivity ??= pedalSensitivity.value;
    return sensitivity == autoPedalSensitivity;
  }
}

enum ERidingMode {
  /// 普通模式，不可以设置限速值
  normal,

  /// 新手模式，可以设置限速值
  newbie,
}
